#! /usr/bin/env python

import mathex

def gen(l):
    if not l:
        yield []
    else:
        for i in range(len(l)):
            for j in  gen(l[:i]+l[i+1:]):
                yield [l[i]] + j

def main():
    for j in range(1,9)[::-1]:
        for i in gen([str(i) for i in range(1,j+1)[::-1]]):
            if mathex.isPrime(int(''.join(i))):
                print ''.join(i)
                1/0

if __name__ == '__main__':
    main()


    
